package com.example.newspublish.controller;

import com.example.newspublish.pojo.form.CategoryForm;
import com.example.newspublish.service.CategoryService;
import com.example.newspublish.util.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "分类管理")
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    CategoryService categoryService;

    @Operation(summary = "增加分类", security = {@SecurityRequirement(name = "Authorization")})
    @PostMapping("/addCategory")
    public Result addCategory(@RequestBody CategoryForm categoryForm) {
        System.out.println(categoryForm.getCategoryName());
        System.out.println("增加分类请求...");
        return categoryService.addCategory(categoryForm);
    }

    @Operation(summary = "获取所有分类")
    @GetMapping("/getAllCategory")
    public Result getCategoryList() {
        return categoryService.getCategoryList();
    }

    @Operation(summary = "删除分类" ,security = {@SecurityRequirement(name = "Authorization")})
    @DeleteMapping("/delete/{id}")
    public Result deleteCategory(@PathVariable("id") Long id) {
        return categoryService.deleteCategoryById(id);
    }

    @Operation(summary = "修改分类",security = {@SecurityRequirement(name = "Authorization")})
    @PutMapping("/update/{id}/{categoryName}")
    public Result updateCategory(@PathVariable("id") Long id,@PathVariable("categoryName") String categoryName) {
        return categoryService.updateCategoryById(id,categoryName);
    }
}
